
from selenium.webdriver.common.by import By

from page.BasePage import BasePage


# 继承BasePage类
class AddPage(BasePage):

    # 定位器，通过元素属性定位元素对象
    username_loc = (By.NAME, 'username')
    password_loc = (By.NAME, 'password')
    sex_loc= (By.NAME,"sex")
    address_loc=(By.NAME,"address")
    add_button_loc = (By.XPATH, '/html/body/form/center/input[1]')


    # 操作
    # 通过继承覆盖（Overriding）方法：如果子类和父类的方法名相同，优先用子类自己的方法。
    # 打开网页
    def open(self):
        # 调用page中的_open打开连接
        self._open(self.base_url, self.pagetitle)

    # 输入用户名：调用send_keys对象，输入用户名
    def input_username(self, username):
        #        self.find_element(*self.username_loc).clear()
        self.find_element(*self.username_loc).send_keys(username)

    # 输入密码：调用send_keys对象，输入密码
    def input_password(self, password):
        #        self.find_element(*self.password_loc).clear()
        self.find_element(*self.password_loc).send_keys(password)

  # 输入性别信息：调用send_keys对象，输入
    def input_sex(self, sex):
        #        self.find_element(*self.password_loc).clear()
        self.find_element(*self.sex_loc).send_keys(sex)

        # 输入性别信息：调用send_keys对象，输入

    def input_address(self, address):
        #        self.find_element(*self.password_loc).clear()
        self.find_element(*self.address_loc).send_keys(address)


    # 点击登录：调用send_keys对象，点击登录
    def click_add_button(self):
        self.find_element(*self.add_button_loc).click()

